package LearnAlgorithm.d_标准查找算法and标准排序算法;

public class a1顺序查找 {

	public static void main(String[] args) {
		int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
		System.out.println("target index: " + shunxuSearch(arr, 8));
	}

	/**
	 * 顺序查找
	 * 无序数组有序数组都可以
	 * O(N)
	 * @param arr
	 * @param key
	 * @return
	 */
	private static int shunxuSearch(int[] arr, int key) {//没什么可讲的，就是挨个对比呗
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == key) {
				return i;
			}
		}
		return -1;
	}
	
}
